package leecode

func lengthOfLongestSubstringLCR(s string) int {
	if len(s) == 0 {
		return 0
	}
	hashMap := make(map[byte]int) //key为窗口中的字符 , value为各个窗口中字符出现的最新下标
	left := -1
	result := 1
	for right := 0; right < len(s); right++ {
		if index, ok := hashMap[s[right]]; ok {
			//如果该元素在窗口内第二次出现
			left = max(left, index)
		}
		hashMap[s[right]] = right
		result = max(result, right-left)
	}
	return result
}
